package com.tangcan.blog.Controller;

import com.alibaba.fastjson.JSONObject;
import com.tangcan.blog.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/Api/User")
@EnableAutoConfiguration
@CrossOrigin(origins = "*",maxAge = 3600 ,allowCredentials="true")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(value = "/UserLogin",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject UserLogin(@RequestBody String data )
    {
        return userService.UserLogin(data);
    }

    @RequestMapping("/GetAll")//Get()传参数
    @ResponseBody
    public JSONObject GetAll(@RequestBody String  data)
    {
        return userService.GetAll(data);
    }

    @RequestMapping("/RefreshToken")//Get()传参数
    @ResponseBody
    public JSONObject RefreshToken(@RequestBody String  data)
    {
        return userService.RefreshToken(data);
    }

    @RequestMapping(value = "/AddUser",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject AddUser(@RequestBody String data )

    {
        return userService.AddUser(data);
    }




    @RequestMapping(value = "/UpdateUser/name",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject UpdateUserName(@RequestBody String data )

    {
        return userService.UpdateUser(data,1);
    }
    @RequestMapping(value = "/UpdateUser/passwd",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject UpdateUserpasswd(@RequestBody String data )

    {
        return userService.UpdateUser(data,2);
    }
    @RequestMapping(value = "/UpdateUser/icon",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject UpdateUsericon(@RequestBody String data )

    {
        return userService.UpdateUser(data,3);
    }
    @RequestMapping(value = "/search",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject SearchUser(@RequestBody String data )

    {
        return userService.SearchUser(data);
    }

    @RequestMapping(value = "/GetAdminNameMap",method = RequestMethod.GET)
    @ResponseBody
    public JSONObject GetAdminNameMap(){
       return userService.GetAdminNameMap();
    }



}
